home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / POLYGON.H < prev    next >
Text File  |  1991-10-17  |  4KB  |  92 lines

  1. /* POLYGON.H: Header file for polygon-filling code, also includes
  2.    a number of useful items for 3D animation. */
  3.  
  4. #define MAX_POLY_LENGTH 4  /* four vertices is the max per poly */
  5. #define SCREEN_WIDTH 320
  6. #define SCREEN_HEIGHT 240
  7. #define PAGE0_START_OFFSET 0
  8. #define PAGE1_START_OFFSET (((long)SCREEN_HEIGHT*SCREEN_WIDTH)/4)
  9. /* Ratio: distance from viewpoint to projection plane / width of
  10.    projection plane. Defines the width of the field of view. Lower
  11.    absolute values = wider fields of view; higher values = narrower */
  12. #define PROJECTION_RATIO   -2.0 /* negative because visible Z
  13.                                    coordinates are negative */
  14. /* Draws the polygon described by the point list PointList in color
  15.    Color with all vertices offset by (X,Y) */
  16. #define DRAW_POLYGON(PointList,NumPoints,Color,X,Y)          \
  17.    Polygon.Length = NumPoints; Polygon.PointPtr = PointList; \
  18.    FillConvexPolygon(&Polygon, Color, X, Y);
  19.  
  20. /* Describes a single 2D point */
  21. struct Point {
  22.    int X;   /* X coordinate */
  23.    int Y;   /* Y coordinate */
  24. };
  25. /* Describes a single 3D point in homogeneous coordinates */
  26. struct Point3 {
  27.    double X;   /* X coordinate */
  28.    double Y;   /* Y coordinate */
  29.    double Z;   /* Z coordinate */
  30.    double W;
  31. };
  32. /* Describes a series of points (used to store a list of vertices that
  33.    describe a polygon; each vertex is assumed to connect to the two
  34.    adjacent vertices, and the last vertex is assumed to connect to the
  35.    first) */
  36. struct PointListHeader {
  37.    int Length;                /* # of points */
  38.    struct Point * PointPtr;   /* pointer to list of points */
  39. };
  40. /* Describes the beginning and ending X coordinates of a single
  41.    horizontal line */
  42. struct HLine {
  43.    int XStart; /* X coordinate of leftmost pixel in line */
  44.    int XEnd;   /* X coordinate of rightmost pixel in line */
  45. };
  46. /* Describes a Length-long series of horizontal lines, all assumed to
  47.    be on contiguous scan lines starting at YStart and proceeding
  48.    downward (used to describe a scan-converted polygon to the
  49.    low-level hardware-dependent drawing code) */
  50. struct HLineList {
  51.    int Length;                /* # of horizontal lines */
  52.    int YStart;                /* Y coordinate of topmost line */
  53.    struct HLine * HLinePtr;   /* pointer to list of horz lines */
  54. };
  55. struct Rect { int Left, Top, Right, Bottom; };
  56. /* Structure describing one face of an object (one polygon) */
  57. struct Face {
  58.    int * VertNums;   /* pointer to vertex ptrs */
  59.    int NumVerts;     /* # of vertices */
  60.    int Color;        /* polygon color */
  61. };
  62. /* Structure describing an object */
  63. struct Object {
  64.    int NumVerts;
  65.    struct Point3 * VertexList;
  66.    struct Point3 * XformedVertexList;
  67.    struct Point3 * ProjectedVertexList;
  68.    struct Point * ScreenVertexList;
  69.    int NumFaces;
  70.    struct Face * FaceList;
  71. };
  72.  
  73. extern void XformVec(double Xform[4][4], double * SourceVec,
  74.    double * DestVec);
  75. extern void ConcatXforms(double SourceXform1[4][4],
  76.    double SourceXform2[4][4], double DestXform[4][4]);
  77. extern void XformAndProjectPoly(double Xform[4][4],
  78.    struct Point3 * Poly, int PolyLength, int Color);
  79. extern int FillConvexPolygon(struct PointListHeader *, int, int, int);
  80. extern void Set320x240Mode(void);
  81. extern void ShowPage(unsigned int StartOffset);
  82. extern void FillRectangleX(int StartX, int StartY, int EndX,
  83.    int EndY, unsigned int PageBase, int Color);
  84. extern void XformAndProjectPoints(double Xform[4][4],
  85.    struct Object * ObjectToXform);
  86. extern void DrawVisibleFaces(struct Object * ObjectToXform);
  87. extern void AppendRotationX(double XformToChange[4][4], double Angle);
  88. extern void AppendRotationY(double XformToChange[4][4], double Angle);
  89. extern void AppendRotationZ(double XformToChange[4][4], double Angle);
  90. extern int DisplayedPage, NonDisplayedPage;
  91. extern struct Rect EraseRect[];
  92.